﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using GtsServer.Service.Model;
using GtsServer.Common;
using GtsServer.Model;

namespace GtsServer.Service.Controller
{
    public class LogController<T, K>
    {
        public static void AddLog(T request, K response, string interfaceName)
        {
            Type type = typeof(T);
            PropertyInfo[] pi = type.GetProperties();
            InitInfo info = new InitInfo();
            int startCount = 0;
            int total_bonus = 0;
            int match_coin = 0;
            int coin = 0;//金币数
            foreach (PropertyInfo item in pi)
            {
                if (item.Name == "info")
                {
                    info = (InitInfo)item.GetValue(request, null);
                }
                else if (item.Name == "classic")
                {
                    GameMainManage mainManage = (GameMainManage)item.GetValue(request, null);
                    startCount = mainManage.start;
                    coin = mainManage.coin;
                }
                else if (item.Name == "match")
                {
                    GameMatchManage gameMatch = (GameMatchManage)item.GetValue(request, null);
                    total_bonus = gameMatch.total_bonus;
                    match_coin = gameMatch.match_coin;
                    startCount = gameMatch.start;
                }
            }
            JournalReportMould model = new JournalReportMould()
            {
                IMSI = info.sim.imsi,
                IMEI = info.sim.imei,
                Mac = info.phone.mac,
                Pid = info.phone.pid,
                UserAccount = info.user == null ? "" : info.user.sys_account,
                UpStream = JsonHelper.ToJson(request),
                DownStream = JsonHelper.ToJson(response),
                RequestTime = DateTime.Now,
                GameNum = startCount,
                Position = interfaceName,
                Total_bonus = total_bonus,
                Match_coin = match_coin,
                GoldNum = coin,
                Vesion = info.version.code.ToString()
            };

            LogMsmqService.LogMsmqServiceClient client = new LogMsmqService.LogMsmqServiceClient();
            client.AddLog(model);

        }
    }
}
